home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c++
- Subject: Re: Destructors in functions
- Date: Sat, 13 Jan 1996 13:52:10 GMT
- Organization: Netcom
- Message-ID: <30f7b83b.67708480@nntp.ix.netcom.com>
- References: <4d7r65$dv9@newsbf02.news.aol.com>
- NNTP-Posting-Host: ix-dc11-30.ix.netcom.com
- X-NETCOM-Date: Sat Jan 13 5:51:54 AM PST 1996
- X-Newsreader: Forte Agent .99c/16.141
-
- weatby@aol.com (Weatby) wrote:
-
- |>If you pass an object to a function, the language makes a bitwise
- copy of
- |>it, local to the function. (Assuming no copy constructor is
- defined.)
- |>Then, on the way out, the function calls the user-defined
- constructor.
- |>
- |>This will cause problems if the object has any pointers in it (if
- they are
- |>released by the destructor, as they 'should' be).
- |>
- |>The question is, why call a destructor on an object for which no
- |>constructor was called? The compiler has probably put the local
- copy on
- |>its stack, and could pop it off on the way out.
- |>
- |>Calling a destructor, automatically, for which no constructor was
- called
- |>seems to be a non-useful feature. Does anyone know why this was
- included
- |>in the language definition?
-
- First, if a bitwise copy is really being done, get a new compiler. It
- should do a memberwise copy. The difference is that any members that
- have copy constructors should be copied using those.
-
- Second, a constructor is being called. The default copy constructor
- does a memberwise copy. If the default copy constructor does not do
- what you want, you need to write your own.
-
-
- Michael M Rubenstein
-